package dda.iot.dll;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/**
 * jna调用ddl动态库函数
 *
 * @author ：cyd
 * @date ：Created in 2020/8/19 14:40
 * @version: 1.0.0
 */
public class LoadDeviceDll {
    public static DeviceDll dll = init("ddadllmain64", DeviceDll.class);

    public static synchronized String getParseData(String deviceType, String data) {
        return dll.ddadevdll(deviceType, data);
    }

    /**
     * ddadll64接口
     */
    public interface DeviceDll extends Library {
        //dll内置函数
        String ddadevdll(String deviceType, String data);
    }

    /**
     * 装载dll接口
     *
     * @param dllPath
     * @param c
     * @return
     */
    public static <T> T init(String dllPath, Class c) {
        //判断是否继承Library
        if (!Library.class.isAssignableFrom(c)) {
            return null;
        }
        // 注意：linux环境，请将路径"/usr/share/deviceDll/win32-x86-64/libddadllmain64.so",调整为实际的"libddadllmain64.so"文件存放路径
        return (T) Native.loadLibrary((Platform.isWindows() ? dllPath : "/usr/share/deviceDll/win32-x86-64/libddadllmain64.so"), c);
    }
}

